#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
#define MAXN 505
using namespace std;
int W, H, N;
int X1[MAXN], X2[MAXN], Y1[MAXN], Y2[MAXN];
bool fld[6 * MAXN][6 * MAXN];
int dxdy[][4] = {
    {0, 0, 1, -1},
    {1, -1, 0, 0}
};
void solve();
int main() {
    cin >> W >> H >> N;
    for (int i = 0; i < N; i++) cin >> X1[i];
    for (int i = 0; i < N; i++) cin >> X2[i];
    for (int i = 0; i < N; i++) cin >> Y1[i];
    for (int i = 0; i < N; i++) cin >> Y2[i];
    solve();
}

// 将连续的数值转换为离散的等级
int compress(int *x1, int *x2, int w) {
    vector<int> res;
    for (int i = 0; i < N; i++) {
        for (int d = -1; d <= 1; d++) {
            int nx1 = x1[i] + d, nx2 = x2[i] + d;
            res.push_back(nx1); res.push_back(nx2);
        }
    }
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    for (int i = 0; i < N; i++) {
        x1[i] = find(res.begin(), res.end(), x1[i]) - res.begin();
        x2[i] = find(res.begin(), res.end(), x2[i]) - res.begin();
    }
    return res.size();
}

void solve() {
    W = compress(X1, X2, W);
    H = compress(Y1, Y2, H);
    memset(fld, 0, sizeof fld);
    for (int i = 0; i < N; i++) {
        for (int j = Y1[i]; j <= Y2[i]; j++) {
            for (int k = X1[i]; k <= X2[i]; k++) {
                fld[j][k] = true;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < W; i++) {
        for (int j = 0; j < H; j++) {
            if (fld[i][j]) continue;
            ans++;
            queue<pair<int, int>> q;
            fld[i][j] = true; q.push({i, j});
            while (!q.empty()) {
                auto x = q.front(); q.pop();
                int sx = x.first, sy = x.second;
                for (int i = 0; i < 4; i++) {
                    int nx = sx + dxdy[0][i], ny = sy + dxdy[0][i];
                    if (nx >= 0 && nx < W && ny >= 0 && ny < H && fld[nx][ny]) {
                        fld[nx][ny] = true;
                        q.push({nx, ny});

                    }
                }
            }
        }
    }
}